#include "cppTutorUtils.h"
#include "cppTutorRequire.h"

#include "cppTutorLog.h"
extern CcppTutorLog Log;

#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <cmath>

CcppTutorUtils :: CcppTutorUtils () {
}

CcppTutorUtils :: ~CcppTutorUtils () {
}

int CcppTutorUtils :: printLineNum (string strFileName) {
    //requireArgs(Argc, 1, "Usage: linenum file\n Adds line numbers to file");
    //ifstream in(Argv[1]);
    //assure(in, Argv[1]);
    ifstream in(strFileName);
    assure(in,strFileName);
    string line;
    vector<string> lines;
    while(getline(in, line)) // Read in entire file
        lines.push_back(line);
    if(lines.size() == 0) {
        return 0;
    }
    int num = 0;
    // Number of lines in file determines width:
    const int width = int(log10((double)lines.size())) + 1;
    for(int i = 0; i < lines.size(); i++) {
        cout.setf(ios::right, ios::adjustfield);
        cout.width(width);
        cout << ++num << ") " << lines[i] << endl;
    }
    return 0;
}